//
//  SnToolManager.m
//  SnapCAD
//
//  Created by Developer on 2025/1/27.
//

#import "SnToolManager.h"
#import "CustomDWGViewer.h"  // 添加自定义DWG查看器

@implementation SnToolManager

+ (NSString *)getCurrentFormattedTime {
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    return [formatter stringFromDate:[NSDate date]];
}

+ (NSString *)getCurrentTimestamp {
    return [NSString stringWithFormat:@"%.0f", [[NSDate date] timeIntervalSince1970]];
}

+ (void)showAlertWithTitle:(NSString *)title 
                   message:(NSString *)message 
                  delegate:(id)delegate 
         cancelButtonTitle:(NSString *)cancelTitle 
         otherButtonTitles:(NSString *)otherTitle 
           completionBlock:(SnCompletionBlock)completionBlock 
               cancelBlock:(SnCancelBlock)cancelBlock 
            viewController:(UIViewController *)viewController {
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:title 
                                                                   message:message 
                                                            preferredStyle:UIAlertControllerStyleAlert];
    
    if (cancelTitle) {
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelTitle 
                                                               style:UIAlertActionStyleCancel 
                                                             handler:^(UIAlertAction * _Nonnull action) {
            if (cancelBlock) {
                cancelBlock();
            }
        }];
        [alert addAction:cancelAction];
    }
    
    if (otherTitle) {
        UIAlertAction *otherAction = [UIAlertAction actionWithTitle:otherTitle 
                                                              style:UIAlertActionStyleDefault 
                                                            handler:^(UIAlertAction * _Nonnull action) {
            if (completionBlock) {
                completionBlock();
            }
        }];
        [alert addAction:otherAction];
    }
    
    [viewController presentViewController:alert animated:YES completion:nil];
}

+ (void)pushCADFileWithModel:(Snmodel *)model 
          navigationController:(UINavigationController *)navigationController {
    
    NSString *inboxPath = model.isFromApplication ? @"Inbox/" : @"";
    NSString *documentPath = [NSHomeDirectory() stringByAppendingString:[NSString stringWithFormat:@"/Documents/%@%@", inboxPath, model.filePath]];
    
    // 使用自定义DWG查看器替代原来的CADViewer
    [CustomDWGViewer pushDWGFile:documentPath 
                        fileName:model.documentName 
              navigationController:navigationController];
}

+ (void)presentCADFileWithModel:(Snmodel *)model 
                 viewController:(UIViewController *)viewController {
    
    NSString *inboxPath = model.isFromApplication ? @"Inbox/" : @"";
    NSString *documentPath = [NSHomeDirectory() stringByAppendingString:[NSString stringWithFormat:@"/Documents/%@%@", inboxPath, model.filePath]];
    
    // 使用自定义DWG查看器替代原来的CADViewer
    [CustomDWGViewer openDWGFile:documentPath 
                        fileName:model.documentName 
                  viewController:viewController];
}

@end